perm filename PROB5.PUB[LSP,JRA]9 blob
sn#172749 filedate 1975-08-09 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 .GROUP
C00005 ENDMK
C⊗;
.GROUP
.CENT(Problems)
.BEGIN CENTERIT;TABIT2(10,23);SELECT 1;
I Use the following definition:
%3
\match[k;m] <=\[null[k] → NO;
\\ null[m] → NO;
\\ eq[first[k];first[m]] → first[k];
\\ %et%* → match[rest[k];rest[m]]]
%1
and evaluate:
%21.%3 match[(X);(X)] %22.%3 match[(A B E);(J O E)] %23.%3 match[(F O O); (BAZ)]
.APART
%1
.GROUP
II Now write your own.
.BEGIN FILL;INDENT 0,7;
%21.%3 among[x;y] <= ... : among%1 is to be a predicate; %3x%1 is an atom; %3y%1 is a list
of atoms. %3among%1 is to return %ef%1 if %3x%1 is not found as an
element of %3y%1; otherwise, %3among%* is to return %et%1.
.END
\e.g. %3among[A;(A B C)] = among[A;(C D E A)] = %et%*
\ among[A1;(A2 B2)] = %ef%*.
%1
.BEGIN FILL;INDENT 0,7;
%22.%3 anywhere[x;y] <= ... : anywhere%1 is a predicate; %3x%1 is an atom; %3y%1 is an arbitrary
sexpr. %3anywhere%1 is to return %et%1 just in the case that %3x%1 appears somewhere in %3y%1.
.END
\e.g. %3anywhere[A;(A B C)] = anywhere[A;((A . B). C)] = %et%*
\ anywhere[A;(B C D)] = %ef%*.
%1
.BEGIN INDENT 0,7;FILL;
%23.%3 collectpair[z;x;y] <= ... : %3x%1 and %3y%* are atoms; %3z%* is an sexpression
some of whose subexpressions, may begin %3(x ...)%* or %3(y ...)%*. %3collectpair%*
is to return a dotted pair whose %3car%*-part is a list of all the occurrences
of %3(x...)%* and whose %3cdr%*-part is a list of all occurrences of %3(y ...)%*.
.END
\e.g. %3collectpair[((A 1)((B . 2)(C A 4)));A;B] = (((A 1)(A 4)).((B . 2)))
%1
.BEGIN INDENT 0,7;FILL;
%24.%3 pred[x] <= ... : x%1 is a positive integer. %3pred%* is a function, returning
the predecessor of its argument.
.END
\e.g. %3pred[3] = 2; pred[0] %1is undefined%*;
\ pred[add1[x]] = x %1 for %3x %c≥%* 0.%1
.END